package com.itheima.reggie.service.impl;

import com.itheima.reggie.entity.User;
import com.itheima.reggie.mapper.UserMapper;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired(required = false)
    private UserMapper userMapper;
    @Override
    public User login(String phone, String code, String codeInsession) {
        User dbUser=null;
        if(codeInsession!=null && code.equalsIgnoreCase(codeInsession)){
            dbUser=userMapper.findByPhone(phone);
            if(dbUser==null){
                dbUser=new User();
                dbUser.setPhone(phone);
                dbUser.setStatus(1);
                userMapper.save(dbUser);
            }
        }
        return dbUser;
    }
}
